/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NotifyExit.java
 *
 * Created on Nov 7, 2011, 5:26:10 PM
 */
package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import control.ControlGame;

/**
 * 
 * @author ADMIN
 */
public class NotifyExit extends javax.swing.JFrame implements ActionListener {

	/** Creates new form NotifyExit */
	public NotifyExit() {
		initComponents();
		setVisible(true);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();
		jPanel1 = new javax.swing.JPanel();
		no_exit_button = new javax.swing.JButton();
		quitAndSave = new javax.swing.JButton();
		exit_button = new javax.swing.JButton();

		jLabel1.setFont(new java.awt.Font("Papyrus", 0, 24)); // NOI18N
		jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel1.setText("Are you sure you want quit game ?");

		jPanel1.setLayout(new java.awt.GridLayout());

		no_exit_button.setFont(new java.awt.Font("Papyrus", 0, 18)); // NOI18N
		no_exit_button.setText("No");
		no_exit_button.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				no_exit_buttonActionPerformed(evt);
			}
		});
		jPanel1.add(no_exit_button);

		quitAndSave.setFont(new java.awt.Font("Papyrus", 0, 18)); // NOI18N
		quitAndSave.setText("Quit And Save");
		jPanel1.add(quitAndSave);

		exit_button.setFont(new java.awt.Font("Papyrus", 0, 18)); // NOI18N
		exit_button.setText("Quit");
		exit_button.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				exit_buttonActionPerformed(evt);
			}
		});
		jPanel1.add(exit_button);
		exit_button.addActionListener(this);
		no_exit_button.addActionListener(this);
		quitAndSave.addActionListener(this);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						layout.createSequentialGroup()
								.addContainerGap(102, Short.MAX_VALUE)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.TRAILING)
												.addComponent(
														jPanel1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														477,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														jLabel1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														500,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(56, 56, 56)));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addComponent(jLabel1,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										146,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addComponent(jPanel1,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										61, Short.MAX_VALUE).addGap(18, 18, 18)));

		pack();
	}// </editor-fold>

	private void exit_buttonActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
	}

	private void no_exit_buttonActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed"
		// desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase
		 * /tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
					.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(NotifyExit.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(NotifyExit.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(NotifyExit.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(NotifyExit.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		}
		// </editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				new NotifyExit().setVisible(true);
			}
		});
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == exit_button) {
			ControlGame.saveGame(false);
			System.out.println("exit ");
			System.exit(EXIT_ON_CLOSE);
		}
		if (e.getSource() == no_exit_button) {
			System.out.println("no exit");
			closeWindown();
		}
		if (e.getSource() == quitAndSave) {
			System.out.println("quit ");
			quitAndSave();
		}

	}

	private void quitAndSave() {
		ControlGame.saveGame(true);
		System.exit(EXIT_ON_CLOSE);
	}

	private void closeWindown() {
		this.setVisible(false);
	}

	// Variables declaration - do not modify
	private javax.swing.JButton exit_button;
	private javax.swing.JButton quitAndSave;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JButton no_exit_button;
	// End of variables declaration
}
